package com.rbac.api.mybatis.mapper;


import com.rbac.api.controller.request.PostRolesListRequest;
import com.rbac.api.mybatis.entity.AdminRolesEntity;
import com.rbac.api.mybatis.entityCus.CusAdRolesListEntity;
import com.rbac.api.mybatis.sqlProvider.AdminRolesSqlProvider;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.Date;
import java.util.List;

public interface AdminRolesMapper {


    ///获取角色列表数据条数
    @SelectProvider(type=AdminRolesSqlProvider.class,method = "getRolesListCountSelective")
    Integer getRolesListCountSelective(@Param("paramRequest") PostRolesListRequest rolesListRequest);
    ///获取角色列表数据list
    @SelectProvider(type=AdminRolesSqlProvider.class,method = "getRolesListDataSelective")
    @Results({
            @Result(column="id", property="id", jdbcType= JdbcType.BIGINT),
            @Result(column="role_diy_no", property="roleDiyNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="role_no", property="roleNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="role_name", property="roleName", jdbcType=JdbcType.VARCHAR),
            @Result(column="role_content", property="roleContent", jdbcType=JdbcType.VARCHAR),
            @Result(column="role_status", property="roleStatus", jdbcType=JdbcType.INTEGER),
            @Result(column="role_member", property="roleMember", jdbcType=JdbcType.INTEGER)
    })
    List<CusAdRolesListEntity> getRolesListDataSelective(@Param("paramRequest") PostRolesListRequest rolesListRequest, @Param("StartRow") Integer StartRow, @Param("pageSize") Integer pageSize);





    ///新增角色，并返回创建的数据id
    @Insert({
            "insert into admin_roles (`role_no`, `role_diy_no`, ",
            "`role_name`, `role_content`,",
            "`create_uid`,`create_time`) ",
            "values (#{roleNo,jdbcType=VARCHAR}, #{roleDiyNo,jdbcType=VARCHAR}, ",
            "#{roleName,jdbcType=VARCHAR}, #{roleContent,jdbcType=VARCHAR},",
            "#{createUid,jdbcType=VARCHAR},#{createTime,jdbcType=TIMESTAMP}) "
    })
    @Options(useGeneratedKeys = true, keyProperty = "id")
    Integer roleAddMapper(AdminRolesEntity record);






    ///角色状态修改
    ///修改后的状态、当前操作人编号、操作时间、数据id、数据当前状态
    @Update({
            "update admin_roles",
            "set role_status = #{roleStatus,jdbcType=INTEGER},",
            "last_update_uid = #{lastUpdateUid,jdbcType=VARCHAR},",
            "last_update_time = #{lastUpdateTime,jdbcType=TIMESTAMP}",
            "where id = #{id,jdbcType=INTEGER}",
            "and role_status = #{nowStatus,jdbcType=INTEGER}"
    })
    Integer saveStatusByIdAndStatusMapper(@Param("roleStatus") Integer roleStatus, @Param("lastUpdateUid") String lastUpdateUid, @Param("lastUpdateTime") Date lastUpdateTime, @Param("id") Integer id, @Param("nowStatus") Integer nowStatus);





    ///根据角色编号获取指定角色数据
    @Select({
            "SELECT\n",
            "`id`,`role_no`,role_diy_no,`role_name`,`role_content`\n",
            "FROM `admin_roles`\n",
            "where `role_no` = #{roleNo,jdbcType=VARCHAR}\n"
    })
    @Results({
            @Result(column="id", property="id", jdbcType= JdbcType.BIGINT),
            @Result(column="role_no", property="roleNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="role_diy_no", property="roleDiyNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="role_name", property="roleName", jdbcType=JdbcType.VARCHAR),
            @Result(column="role_content", property="roleContent", jdbcType=JdbcType.VARCHAR)
    })
    AdminRolesEntity selectInfoByRoleNoMapper(@Param("roleNo") String roleNo);



    ///根据角色编号修改指定角色数据
    @Update({
            "update admin_roles",
            "set role_diy_no = #{roleDiyNo,jdbcType=VARCHAR},",
            "role_name = #{roleName,jdbcType=VARCHAR},",
            "role_content = #{roleContent,jdbcType=VARCHAR},",
            "last_update_uid = #{lastUpdateUid,jdbcType=VARCHAR},",
            "last_update_time = #{lastUpdateTime,jdbcType=TIMESTAMP}",
            "where role_no = #{roleNo,jdbcType=VARCHAR}"
    })
    Integer updateDataByRoleNoMapper(AdminRolesEntity record);



}